package com.wavecoler.professor.servlets;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import com.google.wave.api.AbstractRobot;
import com.google.wave.api.Wavelet;

@SuppressWarnings("serial")
public class WaveCreatorServlet extends AbstractRobot {

	private String consumerToken = "wavecreator@wavecoler.lag.itesm.mx";
	private String tokenSecret = "1Q2duKhqVg9cFPflYTPr9YKoR4-EcfkHp95rWj-kucYkos-Z";
	
	private static Logger LOG = Logger.getLogger(WaveCreatorServlet.class.getName());
	
	public WaveCreatorServlet(){
		setupOAuth(consumerToken, tokenSecret,
		"http://wavecoler.lag.itesm.mx:9898/robot/rpc");
	}
	
	@Override
	protected String getRobotName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected String getRobotProfilePageUrl() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public void createWave(List<String> users) {
		Wavelet newwave;
		Set<String> partset = new HashSet<String>(users);
		// partset.add(robot);
		newwave = newWave("wavecoler.lag.itesm.mx", partset);
		// newwave.setRobotAddress(robot);
		newwave.setTitle("New Wave!");
		newwave.getRootBlip().append("Wave from JSP!");
		try {
			submit(newwave, "http://wavecoler.lag.itesm.mx:9898/robot/rpc");
			LOG.info("New wave submitted - " + newwave.getWaveletId());
		} catch (IOException e1) {
			LOG.info("Error submiting wave: " + e1.getMessage());
		}
	}

}
